<?php
class CommentAction extends PublicAction
{
    public function show()
    {

        $limit =  C('COMMENT_LIST_LIMIT');
        if(!isset($_POST["news"])){
            $this->ajaxReturn("","参数错误~", 0);
            return;
        }
        $newshash = $_POST["news"];
        $page = intval($_POST['p']) ? intval($_POST['p']) : 1;
        $commentDao  = D("Comment");
        $total       = $commentDao->countComment($newshash); 
        $commentList = $commentDao->getComment($newshash,$page,$limit);


        $ret = array(
            "info"=>array("total"=>$total, "page"=>$page, "limit"=>$limit),
            "data"=>$commentList
        );
       $this->ajaxReturn($ret,"查找成功", 1);
    }

    public function add()
    {

        //if(md5($_POST["verify"])!=$_SESSION['verify'])
          // $this->ajaxReturn("", "验证码错误", 0);

        unset($_POST["verify"]);

        $commentDao = D("Comment");
        $commentDao->create();
        $commentDao->content = nl2br(htmlspecialchars($_POST['content']));
        $commentDao->date = time();
        $commentDao->status = 1;
    
        if( ($cid = $commentDao->add())==false)
            $this->ajaxReturn("",$commentDao->getError(), 0);
        else{
            //更新新闻评论的数目
            $newsView = D("NewsView");
            $newsView->incComment($_POST['newshash']);
            $ret = $commentDao->where("commentid=$cid")->find();
              $this->ajaxReturn($ret,"添加成功", 1);
        }
     
    }
}
?>